- /* sdmd2lng.cpp by K.Tsuru */
- // function ID = 316 DRADIX
- /*********************************************************
- SDouble class
- It tries to convert the value "SDouble d" into the form
- d = L * 10^e (long L), L < SlOpMaxValue().
- See "sdbl.h".
- *********************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- bool SDouble::ConvTolongExp(long* L, long* e) const {
- if(Sign(316) == 0){
- *L = *e = 0; return true;
- }
- if(Type() != REAL) SetError(RADIX_ERR, "ConvTolongExp", 316);
- int h = (int)Last(), t = (int)First(), f = h-t, j;
- if(f > 2) return false; // 0.0001 2345 6789 1000 (f=3) > SlOpMaxValue()
- double rdx = DRADIX, r = figure(h), mt = (double)SlOpMaxValue();
- #ifndef NDEBUG
- assert(h);
- #endif
- for(j = h-1; j >= t; j--){
- r += figure(j)*rdx;
- rdx *= DRADIX;
- }
- *e = long(RdxExp() - h)*(long)DFIGURES;
- if(r > mt){
- while( fmod(r, 10.0) < DBL_EPSILON){ //It removes lower zeros.
- (*e)++; r /= 10.0;
- // if( (r < mt) && !( abs(*e) % DFIGURES) ) break; Do not reach here.
- }
- }
- r += ROUND_DBL_INT; //Maybe it is not necessary.
- if(r > mt) return false;
- // convert to long
- if(Sign(316) > 0) *L = (long)r;
- else *L = -(long)r;
- return true;
- }
sdmd2lng.cpp : last modifiled at 2015/11/25 20:14:48(1,245 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).